package com.markhsiu.io.serialize;

public class Performance {

	public static void main(String args[]) {

        final String str = "This is a performance test!";
        
        long startTime_1 = System.nanoTime();
        str.getBytes();
        System.out.println(System.nanoTime() - startTime_1);

        long startTime_2 = System.nanoTime();
        getBytesFast(str);
        System.out.println(System.nanoTime() - startTime_2);
    }

	private static byte[] getBytesFast(String str) {
		final char buffer[] = new char[str.length()];
		final int length = str.length();
		str.getChars(0, length, buffer, 0);
		final byte b[] = new byte[length];
		for (int j = 0; j < length; j++)
			b[j] = (byte) buffer[j];
		return b;
	}
}
